package com.lanou.mynews.news;


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.lanou.mynews.R;


/**
 * Created by dllo on 16/1/18.
 */
public class NewContent extends AppCompatActivity {

    private RequestQueue requestQueue;
    private NewContentEntity.BDKL1R0300963VROEntity datas;
    private TextView textView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.news_content);

        textView = (TextView) findViewById(R.id.news_content_tv);
        requestQueue = Volley.newRequestQueue(this);


        String getUrl = "http://c.3g.163.com/nc/article/" + getIntent().getStringExtra("a") + "/full.html";
        System.out.println("拼接 网址------------" + getUrl);

        StringRequest request = new StringRequest(getUrl, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                if (response != null) {
                    Gson gson = new Gson();
                    //新闻内容字段名是ID名，换成固定内容可破
                    NewContentEntity contentEntity = gson.fromJson(response.replaceFirst(getIntent().getStringExtra("a"), "BDKL1R0300963VRO"), NewContentEntity.class);
                    if (contentEntity != null && contentEntity.getBDKL1R0300963VRO() != null) {
                        datas = contentEntity.getBDKL1R0300963VRO();
                        textView.setText(Html.fromHtml(datas.getBody()));
                    }
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        requestQueue.add(request);


    }
}
